/**
 * 质控病种列表初始化
 */
var SdsQcentity = {
    id: "entityTree",	//表格id
    seItem: null,		//选中的条目
    table: null,
    ztree: null,
    layerIndex: -1,
    cdssRecommendId: 0,
    entityId: 0,
    MatchType: "",
    compare: "",
    PreventUnAC:0,   //阻止反选全部：选择标准字典清除缓存选中医嘱时，需要清空所有选择项。此变量全局实现只反选,不保存。
    cdssRecommendName: "",
    contraindicationName: ''
};

SdsQcentity.onClickEntity = function (e, treeId, treeNode) {
    if (treeNode.pId == null || treeNode.pId == 0) {
        Sys.info("不能选择根节点（"+treeNode.name+"），请重新选择具体方案。");
        return false;
    }
    if (treeNode.name == "推荐护理处置" || treeNode.name == "推荐检验" || treeNode.name == "推荐检查"
        || treeNode.name == "推荐治疗方案" || treeNode.name == "推荐评估量表") {
        Sys.info("不能选择推荐类型（"+treeNode.name+"），请重新选择具体方案。");
        return false;
    }
    SdsQcentity.MatchType = treeNode.pinyin;
    //默认查询已对照
    SdsQcentity.compare = "match";
    $('#NullContraindicationTab').hide();
    $('#ContraindicationTab').show();
    SdsQcentity.LoadContraindicationMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare, SdsQcentity.contraindicationName);
    switch(SdsQcentity.MatchType) {
        case '推荐护理处置'	:
            //$('#OrdTab').css('display','block');
            $('#NullTab').hide();
            $('#LisTab').hide();
            $('#RisTab').hide();
            $('#EvalTab').hide();
            $('#OrdTab').show();
            SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare);
            break;
        case '推荐检验'	:
            $('#NullTab').hide();
            $('#LisTab').show();
            $('#RisTab').hide();
            $('#EvalTab').hide();
            $('#OrdTab').hide();
            SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare);
            break;
        case '推荐检查'	:
            $('#NullTab').hide();
            $('#LisTab').hide();
            $('#RisTab').show();
            $('#EvalTab').hide();
            $('#OrdTab').hide();
            SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare);
            break;
        case '推荐治疗方案'	:
            $('#NullTab').hide();
            $('#LisTab').hide();
            $('#RisTab').hide();
            $('#EvalTab').hide();
            $('#OrdTab').show();
            SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare);
            break;
        case '推荐评估量表'	:
            $('#NullTab').hide();
            $('#LisTab').hide();
            $('#RisTab').hide();
            $('#EvalTab').show();
            $('#OrdTab').hide();
            SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,treeNode.id, SdsQcentity.compare);
            break;
        default:

            break;
    }
    SdsQcentity.cdssRecommendId = treeNode.id;
    SdsQcentity.cdssRecommendName = treeNode.name;
    SdsQcentity.entityId = getCurrentRoot(treeNode);
    //查询质控项目
    //SdsQcentityRule.clearData();
    SdsQcentityRule.setKeyword()
    //SdsQcentityRule.search();
};

SdsQcentity.LoadContraindicationMatch=function(matchType,tId, compare,name){
    SdsQcentity.gridQCStandConMatch = $HUI.datagrid("#gridQCStandConMatch",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        checkOnSelect: false,
        selectOnCheck: true,
        loadMsg:'数据加载中...',
        url:"/cdss/cdssstandardmatch/selectContraindicationMatch",
        method: 'post',
        queryParams:{
            compare: compare,
            matchType: matchType,
            id: tId,
            name: name
        },
        pageSize: 10,
        pageList : [10,50],
        idField:"id",
        columns:[[
            {field:'checked',checkbox:'true',align:'center',width:30,auto:false},
            {field:'name',title:'禁忌症名称',width:350,sortable:true},
            {field:'info',title:'介绍',width:300,align:'center'},
        ]]
        ,onCheck:function(rindex,rowData){
            if (rowData.checked!=1) SdsQcentity.compareCon();
        },
        onUncheck:function(rindex,rowData){
            if (rowData.checked==1)
            {
                SdsQcentity.undoCon(rowData,0);
            }
        },
        onLoadSuccess:function(rowData){
            $('#gridQCStandConMatch').datagrid('clearChecked');
            $(".datagrid-header-check").html("");
            var data = rowData.rows
            $.each(data, function (idx,val) {
                if (val.checked == 1){
                    $('#gridQCStandConMatch').datagrid('checkRow', idx);
                }else {
                    $('#gridQCStandConMatch').datagrid('uncheckRow', idx);
                }
            })
        }
    });
}


SdsQcentity.LoadStandDicMatch=function(matchType,tId, compare){
    SdsQcentity.gridQCStandDicMatch = $HUI.datagrid("#gridQCStandDicMatch",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        checkOnSelect: false,
        selectOnCheck: true,
        onClickRow: onClickRow,
        loadMsg:'数据加载中...',
        url:"/cdss/cdssstandardmatch/selectOrderMatch",
        method: 'post',
        queryParams:{
            compare: compare,
            matchType: matchType,
            id: tId,
            orderKey: Common_GetValue('OrderKey')
        },
        pageSize: 10,
        pageList : [10,50],
        idField:"id",
        columns:[[
            {field:'checked',checkbox:'true',align:'center',width:30,auto:false},
            {field:'description',title:'医嘱项',width:350,sortable:true},
            {field:'orderTypeDesc',title:'分类',width:300,align:'center'},
            {title: '默认', field: 'isDefault', width: 60, align: 'center', valign: 'middle', sortable: true, formatter:function(value,row,index){
                    if(value==1){
                        return "<span class='label label-success'>是</span>";
                    }else{
                        return "<span class='label label-warning'>否</span>";
                    }
                },editor:{
                    type:'combobox',
                    options:{required:true,valueField:'id',textField:'text',editable:false,
                        data:
                            [
                                {'id':1,'text':'是'},
                                {'id':0,'text':'否'}
                            ],
                        onSelect:function (oVal,nVal) {
                            //结束编辑
                            endEditing();
                        }
                    }
                }},
        ]]
        ,
        onCheck:function(rindex,rowData){
            if (rowData.checked!=1) SdsQcentity.compareDic();
        },
        onUncheck:function(rindex,rowData){
            if (rowData.checked==1)
            {
                SdsQcentity.undoDic(rowData,0);
            }
        },
        /*onCheckAll:function(rindex,rowData){
            SdsQcentity.compareDic();
        },
        onUncheckAll:function(rindex,rowData){
            //console.log(rindex)
            if (SdsQcentity.PreventUnAC==0){
                SdsQcentity.undoDic(rindex,1);
            }else{
                SdsQcentity.PreventUnAC=0;
            }
        },*/
        onLoadSuccess:function(rowData){
            $('#gridQCStandDicMatch').datagrid('clearChecked');
            $(".datagrid-header-check").html("");
            var data = rowData.rows
            $.each(data, function (idx,val) {
                if (val.checked == 1){
                    $('#gridQCStandDicMatch').datagrid('checkRow', idx);
                }else {
                    $('#gridQCStandDicMatch').datagrid('uncheckRow', idx);
                }
            })
        }
    });

    var editIndex=undefined;
    var modifyBeforeRow = {};
    var modifyAfterRow = {};

    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#gridQCStandDicMatch').datagrid('validateRow', editIndex)){
            //列表中下拉框实现，修改后把回写feetypename，因为formatter显示的是feetypename字段
            $('#gridQCStandDicMatch').datagrid('endEdit', editIndex);
            modifyAfterRow = $('#gridQCStandDicMatch').datagrid('getRows')[editIndex];
            modifyAfterRow = $('#gridQCStandDicMatch').datagrid('getRows')[editIndex];
            var aStr = JSON.stringify(modifyAfterRow);
            var bStr = JSON.stringify(modifyBeforeRow);
            if(aStr!=bStr){
                //修改默认状态
                var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/updateIsDefault", function (data) {
                    //Sys.success("对照成功!");
                    $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
                    //SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    var tIndex=$('#gridQCStandDicMatch').datagrid('getRowIndex',modifyAfterRow.id);
                    $('#gridQCStandDicMatch').datagrid('updateRow',{
                        index: tIndex,
                        row: {
                            'isDefault':modifyAfterRow.isDefault
                        }
                    });
                }, function (data) {
                    //Sys.error("对照失败!" + data.responseJSON.message + "!");
                    $.messager.alert("错误提示", "数据加载错误!", 'info');
                });
                ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
                ajax.set("orderID",modifyAfterRow.id);
                ajax.set("matchType",SdsQcentity.MatchType);
                ajax.set("isDefault",modifyAfterRow.isDefault);
                ajax.start();
            }
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex!=index) {
            if (endEditing()){
                $('#gridQCStandDicMatch').datagrid('selectRow', index)
                    .datagrid('beginEdit', index);
                editIndex = index;
                modifyBeforeRow = $.extend({},$('#gridQCStandDicMatch').datagrid('getRows')[editIndex]);
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }

}

SdsQcentity.LoadLisDicMatch=function(matchType,tId, compare){
    SdsQcentity.gridLisItemMatch = $HUI.datagrid("#gridLisItemMatch",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        checkOnSelect: false,
        selectOnCheck: true,
        onClickRow: onClickRow,
        loadMsg:'数据加载中...',
        pageSize: 10,
        pageList : [10,50],
        url:"/cdss/cdssstandardmatch/selectLisMatch",
        method: 'post',
        queryParams:{
            compare: compare,
            matchType: matchType,
            id: tId,
            orderKey: Common_GetValue('OrderKey')
        },
        idField:"id",
        columns:[[
            {field:'checked',checkbox:'true',align:'center',width:'30',auto:false},
            {field:'code',title:'检验代码',width:'100',sortable:true},
            {field:'description',title:'检验医嘱',width:'350'},
            {title: '默认', field: 'isDefault', width: 60, align: 'center', valign: 'middle', sortable: true, formatter:function(value,row,index){
                    if(value==1){
                        return "<span class='label label-success'>是</span>";
                    }else{
                        return "<span class='label label-warning'>否</span>";
                    }
                },editor:{
                    type:'combobox',
                    options:{required:true,valueField:'id',textField:'text',editable:false,
                        data:
                            [
                                {'id':1,'text':'是'},
                                {'id':0,'text':'否'}
                            ],
                        onSelect:function (oVal,nVal) {
                            //结束编辑
                            endEditing();
                        }}
                }},
        ]]
        ,
        onCheck:function(rindex,rowData){
            if (rowData.checked!=1) SdsQcentity.compareLis();
        },
        onUncheck:function(rindex,rowData){
            if (rowData.checked==1)
            {
                SdsQcentity.undoLis(rowData,0);
            }

        }/*,
        onCheckAll:function(rindex,rowData){
            SdsQcentity.compareLis();
        },
        onUncheckAll:function(rindex,rowData){
            //console.log(rindex)
            if (SdsQcentity.PreventUnAC==0){
                SdsQcentity.undoLis(rindex,1);
            }else{
                SdsQcentity.PreventUnAC=0;
            }
        }*/
        ,onLoadSuccess:function(rowData){
            $('#gridLisItemMatch').datagrid('clearChecked');
            $(".datagrid-header-check").html("");
            var data = rowData.rows
            $.each(data, function (idx,val) {
                if (val.checked == 1){
                    $('#gridLisItemMatch').datagrid('checkRow', idx);
                }else {
                    $('#gridLisItemMatch').datagrid('uncheckRow', idx);
                }
            })
        }
    });

    var editIndex=undefined;
    var modifyBeforeRow = {};
    var modifyAfterRow = {};

    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#gridLisItemMatch').datagrid('validateRow', editIndex)){
            //列表中下拉框实现，修改后把回写feetypename，因为formatter显示的是feetypename字段
            $('#gridLisItemMatch').datagrid('endEdit', editIndex);
            modifyAfterRow = $('#gridLisItemMatch').datagrid('getRows')[editIndex];
            modifyAfterRow = $('#gridLisItemMatch').datagrid('getRows')[editIndex];
            var aStr = JSON.stringify(modifyAfterRow);
            var bStr = JSON.stringify(modifyBeforeRow);
            if(aStr!=bStr){

                //修改默认状态
                var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/updateIsDefault", function (data) {
                    //Sys.success("对照成功!");
                    $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
                    //SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    var tIndex=$('#gridLisItemMatch').datagrid('getRowIndex',modifyAfterRow.id);
                    $('#gridLisItemMatch').datagrid('updateRow',{
                        index: tIndex,
                        row: {
                            'isDefault':modifyAfterRow.isDefault
                        }
                    });
                }, function (data) {
                    //Sys.error("对照失败!" + data.responseJSON.message + "!");
                    $.messager.alert("错误提示", "数据加载错误!", 'info');
                });
                ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
                ajax.set("orderID",modifyAfterRow.id);
                ajax.set("matchType",SdsQcentity.MatchType);
                ajax.set("isDefault",modifyAfterRow.isDefault);
                ajax.start();
            }
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex!=index) {
            if (endEditing()){
                $('#gridLisItemMatch').datagrid('selectRow', index)
                    .datagrid('beginEdit', index);
                editIndex = index;
                modifyBeforeRow = $.extend({},$('#gridLisItemMatch').datagrid('getRows')[editIndex]);
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }

}

SdsQcentity.LoadRisDicMatch=function(matchType,tId, compare){
    SdsQcentity.gridRisItemMatch = $HUI.datagrid("#gridRisItemMatch",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        checkOnSelect: false,
        selectOnCheck: true,
        onClickRow: onClickRow,
        loadMsg:'数据加载中...',
        pageSize: 10,
        pageList : [10,50],
        url:"/cdss/cdssstandardmatch/selectRisMatch",
        method: 'post',
        queryParams:{
            compare: compare,
            matchType: matchType,
            id: tId,
            orderKey: Common_GetValue('OrderKey')
        },
        idField:"id",
        columns:[[
            {field:'checked',checkbox:'true',align:'center',width:'30',auto:false},
            {field:'code',title:'检查代码',width:'100',sortable:true},
            {field:'description',title:'检查医嘱',width:'350'},
            {title: '默认', field: 'isDefault', width: 60, align: 'center', valign: 'middle', sortable: true, formatter:function(value,row,index){
                    if(value==1){
                        return "<span class='label label-success'>是</span>";
                    }else{
                        return "<span class='label label-warning'>否</span>";
                    }
                },editor:{
                    type:'combobox',
                    options:{required:true,valueField:'id',textField:'text',editable:false,
                        data:
                            [
                                {'id':1,'text':'是'},
                                {'id':0,'text':'否'}
                            ],
                        onSelect:function (oVal,nVal) {
                            //结束编辑
                            endEditing();
                        }}
                }},

        ]]
        ,
        onCheck:function(rindex,rowData){
            //var chkRows = SdsQcentity.gridRisItemMatch.getChecked();
            //console.log(chkRows)
            if (rowData.checked!=1) SdsQcentity.compareRis();
        },
        onUncheck:function(rindex,rowData){
            //console.log(rowData)
            if (rowData.checked==1)
            {
                SdsQcentity.undoRis(rowData,0);
            }
        },
        /*onCheckAll:function(rindex,rowData){
            SdsQcentity.compareRis();
        },
        onUncheckAll:function(rindex,rowData){
            //console.log(rindex)
            if (SdsQcentity.PreventUnAC==0){
                SdsQcentity.undoRis(rindex,1);
            }else{
                SdsQcentity.PreventUnAC=0;
            }
        },*/
        onLoadSuccess:function(data){
            $('#gridRisItemMatch').datagrid('clearChecked');
            $(".datagrid-header-check").html("");
            var data = data.rows
            $.each(data, function (idx,val) {
                if (val.checked == 1){
                    $('#gridRisItemMatch').datagrid('checkRow', idx);
                }else {
                    $('#gridRisItemMatch').datagrid('uncheckRow', idx);
                }
            })
        }
    });

    var editIndex=undefined;
    var modifyBeforeRow = {};
    var modifyAfterRow = {};

    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#gridRisItemMatch').datagrid('validateRow', editIndex)){
            //列表中下拉框实现，修改后把回写feetypename，因为formatter显示的是feetypename字段
            $('#gridRisItemMatch').datagrid('endEdit', editIndex);
            modifyAfterRow = $('#gridRisItemMatch').datagrid('getRows')[editIndex];
            modifyAfterRow = $('#gridRisItemMatch').datagrid('getRows')[editIndex];
            var aStr = JSON.stringify(modifyAfterRow);
            var bStr = JSON.stringify(modifyBeforeRow);
            if(aStr!=bStr){
                //修改默认状态
                var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/updateIsDefault", function (data) {
                    //Sys.success("对照成功!");
                    $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
                    //SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    var tIndex=$('#gridRisItemMatch').datagrid('getRowIndex',modifyAfterRow.id);
                    $('#gridRisItemMatch').datagrid('updateRow',{
                        index: tIndex,
                        row: {
                            'isDefault':modifyAfterRow.isDefault
                        }
                    });
                }, function (data) {
                    //Sys.error("对照失败!" + data.responseJSON.message + "!");
                    $.messager.alert("错误提示", "数据加载错误!", 'info');
                });
                ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
                ajax.set("orderID",modifyAfterRow.id);
                ajax.set("matchType",SdsQcentity.MatchType);
                ajax.set("isDefault",modifyAfterRow.isDefault);
                ajax.start();
            }
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex!=index) {
            if (endEditing()){
                $('#gridRisItemMatch').datagrid('selectRow', index)
                    .datagrid('beginEdit', index);
                editIndex = index;
                modifyBeforeRow = $.extend({},$('#gridRisItemMatch').datagrid('getRows')[editIndex]);
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }

}

SdsQcentity.LoadStandEvalMatch=function(matchType,tId, compare){
    SdsQcentity.gridEvalMatch = $HUI.datagrid("#gridEvalMatch",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        checkOnSelect: false,
        selectOnCheck: true,
        onClickRow: onClickRow,
        autoSave:true,
        loadMsg:'数据加载中...',
        url:"/cdss/cdssstandardmatch/selectEvalMatch",
        method: 'post',
        queryParams:{
            compare: compare,
            matchType: matchType,
            id: tId,
            orderKey: Common_GetValue('OrderKey')
        },
        pageSize: 10,
        pageList : [10,50],
        idField:"id",
        columns:[[
            {field:'checked',checkbox:'true',align:'center',width:30,auto:false},
            {field:'code',title:'评估表代码',width:350,sortable:true},
            {field:'description',title:'描述',width:300,align:'center'},
            {title: '默认', field: 'isDefault', width: 60, align: 'center', valign: 'middle', sortable: true, formatter:function(value,row,index){
                    if(value==1){
                        return "<span class='label label-success'>是</span>";
                    }else{
                        return "<span class='label label-warning'>否</span>";
                    }
                },editor:{
                    type:'combobox',
                    options:{required:true,valueField:'id',textField:'text',editable:false,
                        data:
                            [
                                {'id':1,'text':'是'},
                                {'id':0,'text':'否'}
                            ],
                        onSelect:function (oVal,nVal) {
                            //结束编辑
                            endEditing();
                        }}
                }},

        ]]
        ,
        onCheck:function(rindex,rowData){
            if (rowData.checked!=1) SdsQcentity.compareEval();
        },
        onUncheck:function(rindex,rowData){
            if (rowData.checked==1)
            {
                SdsQcentity.undoEval(rowData,0);
            }
        },
        /*onCheckAll:function(rindex,rowData){
            SdsQcentity.compareEval();
        },
        onUncheckAll:function(rindex,rowData){
            //console.log(rindex)
            if (SdsQcentity.PreventUnAC==0){
                SdsQcentity.undoEval(rindex,1);
            }else{
                SdsQcentity.PreventUnAC=0;
            }
        }
        ,*/
        onLoadSuccess:function(rowData){
            $('#gridEvalMatch').datagrid('clearChecked');
            $(".datagrid-header-check").html("");
            var data = rowData.rows
            $.each(data, function (idx,val) {
                if (val.checked == 1){
                    $('#gridEvalMatch').datagrid('checkRow', idx);
                }else {
                    $('#gridEvalMatch').datagrid('uncheckRow', idx);
                }
            })
        }
    });

    var editIndex=undefined;
    var modifyBeforeRow = {};
    var modifyAfterRow = {};

    function endEditing(){
        if (editIndex == undefined){return true}
        if ($('#gridEvalMatch').datagrid('validateRow', editIndex)){
            //列表中下拉框实现，修改后把回写feetypename，因为formatter显示的是feetypename字段
            $('#gridEvalMatch').datagrid('endEdit', editIndex);
            modifyAfterRow = $('#gridEvalMatch').datagrid('getRows')[editIndex];
            modifyAfterRow = $('#gridEvalMatch').datagrid('getRows')[editIndex];
            var aStr = JSON.stringify(modifyAfterRow);
            var bStr = JSON.stringify(modifyBeforeRow);
            if(aStr!=bStr){
                //修改默认状态
                var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/updateIsDefault", function (data) {
                    //Sys.success("对照成功!");
                    $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
                    //SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    var tIndex=$('#gridEvalMatch').datagrid('getRowIndex',modifyAfterRow.id);
                    $('#gridEvalMatch').datagrid('updateRow',{
                        index: tIndex,
                        row: {
                            'isDefault':modifyAfterRow.isDefault
                        }
                    });
                }, function (data) {
                    //Sys.error("对照失败!" + data.responseJSON.message + "!");
                    $.messager.alert("错误提示", "数据加载错误!", 'info');
                });
                ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
                ajax.set("orderID",modifyAfterRow.id);
                ajax.set("matchType",SdsQcentity.MatchType);
                ajax.set("isDefault",modifyAfterRow.isDefault);
                ajax.start();
            }
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex!=index) {
            if (endEditing()){
                $('#gridEvalMatch').datagrid('selectRow', index)
                    .datagrid('beginEdit', index);
                editIndex = index;
                modifyBeforeRow = $.extend({},$('#gridEvalMatch').datagrid('getRows')[editIndex]);
            } else {
                $('#dg').datagrid('selectRow', editIndex);
            }
        }
    }





}

SdsQcentity.compareRis = function(){
    var chkRows = SdsQcentity.gridRisItemMatch.getChecked();
    var orderIDStr = ""
    for (var i=0;i<chkRows.length;i++) {
        var tmpRow = chkRows[i]
        var orderID = tmpRow.id
        orderIDStr += orderID+","
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/compare", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.undoRis = function(chkRows,flag){
    var orderIDStr = ""
    if (flag == 0){
        orderIDStr = chkRows.id+","
    }else {
        for (var i=0;i<chkRows.length;i++) {
            var tmpRow = chkRows[i]
            var orderID = tmpRow.id
            orderIDStr += orderID+","
        }
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/undo", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.compareLis = function(){
    var chkRows = SdsQcentity.gridLisItemMatch.getChecked();
    var orderIDStr = ""
    for (var i=0;i<chkRows.length;i++) {
        var tmpRow = chkRows[i]
        var orderID = tmpRow.id
        orderIDStr += orderID+","
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/compare", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.undoLis = function(chkRows,flag){
    var orderIDStr = ""
    if (flag == 0){
        orderIDStr = chkRows.id+","
    }else {
        for (var i=0;i<chkRows.length;i++) {
            var tmpRow = chkRows[i]
            var orderID = tmpRow.id
            orderIDStr += orderID+","
        }
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/undo", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.compareCon = function(){
    var chkRows = SdsQcentity.gridQCStandConMatch.getChecked();
    var contraindicationIDStr = ""
    for (var i=0;i<chkRows.length;i++) {
        var tmpRow = chkRows[i]
        var contraindicationID = tmpRow.id
        contraindicationIDStr += contraindicationID+","
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/comparecon", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadContraindicationMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare, SdsQcentity.contraindicationName);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssId",SdsQcentity.cdssRecommendId);
    ajax.set("contraindicationIDStr",contraindicationIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.undoCon = function(chkRows,flag){
    var contraindicationIDStr = ""
    if (flag == 0){
        contraindicationIDStr = chkRows.id+","
    }else {
        for (var i=0;i<chkRows.length;i++) {
            var tmpRow = chkRows[i]
            var contraindicationID = tmpRow.id
            contraindicationIDStr += contraindicationID+","
        }
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/undocon", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadContraindicationMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare, SdsQcentity.contraindicationName);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssId",SdsQcentity.cdssRecommendId);
    ajax.set("contraindicationIDStr",contraindicationIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.compareDic = function(){
    var chkRows = SdsQcentity.gridQCStandDicMatch.getChecked();
    var orderIDStr = ""
    for (var i=0;i<chkRows.length;i++) {
        var tmpRow = chkRows[i]
        var orderID = tmpRow.id
        orderIDStr += orderID+","
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/compare", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.undoDic = function(chkRows,flag){
    var orderIDStr = ""
    if (flag == 0){
        orderIDStr = chkRows.id+","
    }else {
        for (var i=0;i<chkRows.length;i++) {
            var tmpRow = chkRows[i]
            var orderID = tmpRow.id
            orderIDStr += orderID+","
        }
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/undo", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.compareEval = function(){
    var chkRows = SdsQcentity.gridEvalMatch.getChecked();
    var orderIDStr = ""
    for (var i=0;i<chkRows.length;i++) {
        var tmpRow = chkRows[i]
        var orderID = tmpRow.id
        orderIDStr += orderID+","
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/compare", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

SdsQcentity.undoEval = function(chkRows,flag){
    var orderIDStr = ""
    if (flag == 0){
        orderIDStr = chkRows.id+","
    }else {
        for (var i=0;i<chkRows.length;i++) {
            var tmpRow = chkRows[i]
            var orderID = tmpRow.id
            orderIDStr += orderID+","
        }
    }

    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/undo", function (data) {
        //Sys.success("对照成功!");
        $.messager.popover({msg: '刷新对照信息成功！',type:'success',timeout: 1000});
        SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
    }, function (data) {
        //Sys.error("对照失败!" + data.responseJSON.message + "!");
        $.messager.alert("错误提示", "数据加载错误!", 'info');
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("orderIDStr",orderIDStr);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.start();
}

function getCurrentRoot(treeNode){
    if(treeNode.getParentNode() != null){
        var parentNode = treeNode.getParentNode();
        return getCurrentRoot(parentNode);
    }else {
        return treeNode.id;
    }
}

//取值
function Common_GetValue() {
    var itmValue = '';

    if (typeof(arguments[0]) !== 'string') return '';
    if (arguments[0] == '') return '';

    var $this = $('#'+ arguments[0]);
    if ($this.length < 1) return '';

    var className = $this.attr("class").split(' ')[0];

    if (className == 'textbox') {  //文本框
        itmValue = $this.val();
    }else if (className == 'hisui-numberbox') {  //数字
        itmValue = $this.val();
    }else if (className == 'hisui-datebox') {  //日期
        itmValue = $this.datebox('getValue');
    }else if (className == 'hisui-timespinner') {  //时间框
        itmValue = $this.timespinner('getValue');
    }else if (className == 'hisui-combobox') {  //下拉框（多选下拉框没有封装）
        itmValue = $this.combobox('getValue');
    }else if (className == 'hisui-switchbox') {  //开关
        itmValue = $this.switchbox('getValue');
    }else if (className == 'hisui-checkbox') {  // 单个复选框
        itmValue = $this.checkbox('getValue');
    }else if (className == 'hisui-radio') {  //单个单选框
        itmValue = $this.radio('getValue');
    }else if (className == 'hisui-searchbox') {  //查询框框
        itmValue = $this.searchbox('getValue');
    }

    return itmValue;
}

/**
 * 病种筛查配置管理初始化
 */
var SdsQcentityRule = {
    id: "SdsQcentityRuleTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

SdsQcentityRule.setKeyword = function (){
    var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/getKeyword", function (data) {
        $('#param2').val(data);
    }, function (data) {
    });
    ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
    ajax.set("matchType",SdsQcentity.MatchType);
    ajax.set("entityId",SdsQcentity.entityId);
    ajax.start();

}

/**
 * 初始化表格的列
 */
SdsQcentityRule.initColumn = function () {
    return [
        {field: 'selectItem', radio: true, visible: false},
        {field: 'indNo', width: 1, align: 'center', valign: 'middle', sortable: false},
        {title: '病种ID', field: 'entityId', width: 1, align: 'center', valign: 'middle', sortable: false, visible: false},
        {title: '项目类型', field: 'ruleType', width: 3, align: 'center', valign: 'middle', sortable: false, formatter:function(value,row,index) {
                if (value == 1) {
                    return "准入";
                } else {
                    return "排除";
                }
            }},
        {title: '是否有效', field: 'isActive', width: 2, align: 'center', valign: 'middle', sortable: false, formatter:function(value,row,index) {
                if (value == 1) {
                    return "<span class='label label-success'>是</span>";
                } else {
                    return "<span class='label label-warning'>否</span>";
                }
            }},
        {title: '筛查描述', field: 'ruleDesc', width: 5, align: 'left', valign: 'middle', sortable: false},
        {title: '筛查函数', field: 'expressId', width: 3, align: 'center', valign: 'middle', sortable: false,  formatter:function(value,row,index) {
                var expObj = $("#expressId option");
                var expDesc = "";
                expObj.each(function(i){
                    if(value == expObj[i].value) {
                        expDesc =  expObj[i].innerHTML;
                    }
                });
                return expDesc;
            }},
        {title: '筛查入参', field: 'param', width: 3, align: 'center', valign: 'middle', sortable: false},
        {title: '预留参数', field: 'param2', width: 3, align: 'center', valign: 'middle', sortable: false}];
};

function pagerFilter(data) {
    if (typeof data.length == 'number' && typeof data.splice == 'function') {// is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {pageNumber: pageNum, pageSize: pageSize});
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}

/**
 * 选中规则行填充上方控件
 */
SdsQcentityRule.fillData = function (obj,$ele,field) {
    if ($($ele)[0].className == 'info') {
        SdsQcentityRule.clearData();
        $($ele).removeClass('info');
    } else {
        SdsQcentityRule.seItem = obj;
        $('#ruleType').combobox('setValue', obj.ruleType);
        $('#ruleDesc').val(obj.ruleDesc);
        $('#linkDept').combobox('setValues', obj.linkDept.split("#"));//多选
        $('#expressId').combobox('setValue', obj.expressId);
        $('#param').val(obj.param);
        $('#param2').val(obj.param2);
        $('#param3').val(obj.param3);
        $('#isActive').checkbox('setValue', obj.isActive == 1 ? true : false);
        // 改变选中行背景色
        $('#SdsQcentityRuleTable .info').removeClass('info');//移除class
        $($ele).addClass('info');//添加class
    }
}

/**
 * 清除上方控件数据
 */
SdsQcentityRule.clearData = function ( ) {
    SdsQcentityRule.seItem = null;
    $('#ruleType').combobox('clear');
    $('#ruleDesc').val('');
    $('#linkDept').combobox('clear');
    $('#expressId').combobox('clear');
    $('#param').val('');
    $('#param2').val('');
    $('#param3').val('');
    $('#isActive').checkbox('clear');
    // 改变选中行背景色
    $('#SdsQcentityRuleTable .info').removeClass('info');//移除class
}

/**
 * 检查是否选中病种
 */
SdsQcentityRule.check = function () {
    if (SdsQcentity.cdssRecommendId) {
        return true;
    } else {
        Sys.info("请先选中某一方案！");
        return false;
    }
};

/**
 * 验证数据是否为空
 */
SdsQcentityRule.validate = function (flag) {
    var errinfo = "";
    if (flag == "1"){
        if ($("#param2").val()=="") {
            errinfo = errinfo + "请填写关键字再保存!<br>";
        }
    }
    if (flag == "2"){
        if ($("#param3").val()=="") {
            errinfo = errinfo + "请填写关键字再查询!<br>";
        }
    }

    if (errinfo) {
        $.messager.alert("错误提示", errinfo, 'info');
        return false;
    }
    return true;
}

/**
 * 查询禁忌症
 * @param id
 */
SdsQcentityRule.searchCon = function (id) {
    var flag = false;
    if (this.check()) {
        flag = true;
    }
    if (flag) {
        if (!this.validate("2")) {
            return;
        }
        SdsQcentity.contraindicationName = $("#param3").val();
        //.log(SdsQcentity.contraindicationName)
        SdsQcentity.compare = "search";
        SdsQcentity.gridQCStandConMatch.load({
            compare: SdsQcentity.compare,
            matchType: "关联禁忌症",
            id: SdsQcentity.cdssRecommendId,
            name: SdsQcentity.contraindicationName
        })
    }
};

/**
 * 编辑筛查配置
 */
SdsQcentityRule.edit = function (id) {
    var flag = false;
    if (this.check()) {
        flag = true;
    }
    if (flag) {
        if (!this.validate("1")) {
            return;
        }
        var queryData = {};
        queryData['cdssRecommendId'] = SdsQcentity.cdssRecommendId;
        queryData['qcentityId'] = SdsQcentity.entityId;
        queryData['recommendType'] = SdsQcentity.MatchType;
        queryData['keyword'] = encodeURIComponent($("#param2").val());
        //提交信息
        var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/updateKeyword", function (res) {
            Sys.success(res.message);
            //SdsQcentityRule.table.refresh();
        }, function (data) {
            Sys.error("添加失败!" + res.message + "!");
        });
        ajax.setData(queryData);
        ajax.start();
    }
};

SdsQcentityRule.import = function () {
    var index = Sys.open('导入CAP方案对照关键字', Sys.backendPath + '/cdss/cdssstandardmatch/to_import', ['550px', '300px']);
    this.layerIndex = index;
};

/**
 * 自动匹配
 */
SdsQcentityRule.autoCompare = function (){
    var operation = function(){
        var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/autoCompare", function (data) {
            Sys.success("自动匹配成功!");
            switch(SdsQcentity.MatchType) {
                case '推荐护理处置'	:
                    //$('#OrdTab').css('display','block');
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').show();
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检验'	:
                    $('#NullTab').hide();
                    $('#LisTab').show();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检查'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').show();
                    $('#EvalTab').hide();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐治疗方案'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').show();
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐评估量表'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').show();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                default:

                    break;
            }
        }, function (data) {
            Sys.error("自动匹配失败!" + data.responseJSON.message + "!");
        });
        ajax.set("cdssRecommendId",SdsQcentity.cdssRecommendId);
        ajax.set("cdssRecommendName",SdsQcentity.cdssRecommendName);
        ajax.set("recommendType",SdsQcentity.MatchType);
        ajax.start();
    };
    Sys.confirm("是否对" + SdsQcentity.cdssRecommendName + "节点进行自动匹配?",operation);
}

SdsQcentityRule.autoCompareAll = function (){
    var operation = function(){
        var ajax = new $ax(Sys.backendPath + "/cdss/cdssstandardmatch/autoCompare", function (data) {
            Sys.success("自动匹配成功!");
            switch(SdsQcentity.MatchType) {
                case '推荐护理处置'	:
                    //$('#OrdTab').css('display','block');
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').show();
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检验'	:
                    $('#NullTab').hide();
                    $('#LisTab').show();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检查'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').show();
                    $('#EvalTab').hide();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐治疗方案'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').hide();
                    $('#OrdTab').show();
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐评估量表'	:
                    $('#NullTab').hide();
                    $('#LisTab').hide();
                    $('#RisTab').hide();
                    $('#EvalTab').show();
                    $('#OrdTab').hide();
                    SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                default:

                    break;
            }
        }, function (data) {
            Sys.error("自动匹配失败!" + data.responseJSON.message + "!");
        });
        ajax.set("cdssRecommendId","");
        ajax.set("cdssRecommendName","");
        ajax.set("recommendType","");
        ajax.start();
    };
    Sys.confirm("是否对全部字典进行自动匹配?",operation);
}

SdsQcentityRule.compareConAll = function (){
    SdsQcentity.compare = "all";
    SdsQcentity.gridQCStandConMatch.load({
        compare: SdsQcentity.compare,
        matchType: "关联禁忌症",
        id: SdsQcentity.cdssRecommendId
    })
}

SdsQcentityRule.compareConYes = function (){
    SdsQcentity.compare = "match";
    SdsQcentity.gridQCStandConMatch.load({
        compare: SdsQcentity.compare,
        matchType: "关联禁忌症",
        id: SdsQcentity.cdssRecommendId
    })
}

SdsQcentityRule.compareConNo = function (){
    SdsQcentity.compare = "noMatch";
    SdsQcentity.gridQCStandConMatch.load({
        compare: SdsQcentity.compare,
        matchType: "关联禁忌症",
        id: SdsQcentity.cdssRecommendId
    })
}

SdsQcentityRule.compareAll = function (){
    SdsQcentity.compare = "all";
    switch(SdsQcentity.MatchType) {
        case '推荐护理处置'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐护理处置",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检验'	:
            SdsQcentity.gridLisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检验",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检查'	:
            SdsQcentity.gridRisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检查",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐治疗方案'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐治疗方案",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐评估量表'	:
            SdsQcentity.gridEvalMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐评估量表",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        default:
            break;
    }
}

SdsQcentityRule.compareNo = function (){
    SdsQcentity.compare = "noMatch";
    switch(SdsQcentity.MatchType) {
        case '推荐护理处置'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐护理处置",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检验'	:
            //SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, "all");
            SdsQcentity.gridLisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检验",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检查'	:
            SdsQcentity.gridRisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检查",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐治疗方案'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐治疗方案",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐评估量表'	:
            SdsQcentity.gridEvalMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐评估量表",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        default:
            break;
    }
}

SdsQcentityRule.compareYes = function (){
    SdsQcentity.compare = "match";
    switch(SdsQcentity.MatchType) {
        case '推荐护理处置'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐护理处置",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检验'	:
            SdsQcentity.gridLisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检验",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐检查'	:
            SdsQcentity.gridRisItemMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐检查",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐治疗方案'	:
            SdsQcentity.gridQCStandDicMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐治疗方案",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        case '推荐评估量表'	:
            SdsQcentity.gridEvalMatch.load({
                compare: SdsQcentity.compare,
                matchType: "推荐评估量表",
                id: SdsQcentity.cdssRecommendId
            })
            break;
        default:
            break;
    }
}


/**
 * 查询病种筛查配置列表
 */
SdsQcentityRule.search = function () {
    var queryData = {};
    queryData['entityId'] = SdsQcentity.entityId;
    //SdsQcentityRule.table.refresh({query: queryData, pageNumber: 1});
};

$(function () {
    //查询病种树
    var ztree = new $ZTree("entityTree", Sys.backendPath + "/cdss/cdssstandardmatch/tree/");
    ztree.bindOnClick(SdsQcentity.onClickEntity);
    ztree.init();
    SdsQcentity.ztree = ztree;
    fuzzySearch('entityTree','#seachKey',null,true);

    $('#OrderKey').searchbox({
        searcher:function(value){
            switch(SdsQcentity.MatchType) {
                case '推荐护理处置'	:
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检验'	:
                    SdsQcentity.LoadLisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐检查'	:
                    SdsQcentity.LoadRisDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐治疗方案'	:
                    SdsQcentity.LoadStandDicMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                case '推荐评估量表'	:
                    SdsQcentity.LoadStandEvalMatch(SdsQcentity.MatchType,SdsQcentity.cdssRecommendId, SdsQcentity.compare);
                    break;
                default:

                    break;
            }
        },
        prompt:'医嘱关键字'
    });

    //项目规则获取
    /*var defaultColunms = SdsQcentityRule.initColumn();
    var table = new BSTable(SdsQcentityRule.id, Sys.backendPath + "/sds/sdsqcentityrule/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(10);
    table.setSubHeight(-40);
    table.setShowExport(false);
    table.setShowRefresh(false);
    table.setShowToggle(false);
    table.setShowColumns(false);
    table.setOnClickRow(SdsQcentityRule.fillData);
    table.setQueryParams({"entityId":0});
    SdsQcentityRule.table = table.init();*/
});
